import React from 'react';
import { connect, } from 'react-redux';
import { addTodoItem, deleteTodoItem, } from '../../../redux/actions/action';

const Button = (props) => {

  const { type, onClickAddItem, onClickDeleteItem, addTodoItem, deleteTodoItem, } = props;

  const onClickActionTodoList = (index) => {
    type === "add" ? addTodoItem(onClickAddItem()): deleteTodoItem(onClickDeleteItem());
  };

  return (
    <div>
      <button onClick={ onClickActionTodoList }>
        { type === "add" ? "添加": "删除" }
      </button>
    </div>
  );
};

const mapDispatchToProps = {
  addTodoItem,
  deleteTodoItem,
};

export default connect(null, mapDispatchToProps)(Button);
